package com.zcf.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.zcf.common.json.Body;
import com.zcf.common.result.PageResult;
import com.zcf.common.result.ResultVo;
import com.zcf.mapper.TaocanMapper;
import com.zcf.mapper.TaocanpMapper;
import com.zcf.pojo.Dining;
import com.zcf.pojo.Taocan;
import com.zcf.pojo.Taocanp;
import com.zcf.service.TaocanService;
import com.zcf.utils.Hutool;
import com.zcf.vo.in.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhouzhuang
 * @since 2018-11-28
 */
@Service
public class TaocanServiceImpl extends ServiceImpl<TaocanMapper, Taocan> implements TaocanService {

	@Autowired
	private TaocanMapper taocanMapper;

	@Autowired
	private TaocanpMapper taocanpMapper;
	public Body addTaocanp(  String  price, String pid, String tid) {

		Taocanp add = new Taocanp();
		add.setId(Hutool.getId());
		add.setPrice(Double.parseDouble(price));
		add.setPid(pid);
		add.setTid(Integer.parseInt(tid));
		add.setSum(1);
		Integer insert = taocanpMapper.insert(add);
		if (insert > 0) {
			return Body.newInstance(add);
		}
		return Body.newInstance(501, "上传套餐有误");
	}
	public Body addTaocan( String name, String content, String dinid, String sale, String zksale ,int xh,String img) {

		Taocan add = new Taocan();
		add.setId(Hutool.getId());
		add.setName(name);
		add.setContent(content);
		add.setDinid(dinid);
		add.setSale(sale);
		add.setZksale(zksale);
		add.setXh(xh);
		add.setImg(img);
		Integer insert = taocanMapper.insert(add);
		if (insert > 0) {
			return Body.newInstance(add);
		}
		return Body.newInstance(501, "上传套餐有误");
	}
	public Body upTaocan(String id, String name, String content, String dinid, String sale, String zksale,int xh,String img) {
		Taocan one = taocanMapper.selectById(id);
		if (one != null && !"".equals(one)) {
			one.setName(name);
			one.setContent(content);
			one.setDinid(dinid);
			one.setSale(sale);
			one.setZksale(zksale);
			one.setXh(xh);
			one.setImg(img);
			Integer b = taocanMapper.updateById(one);
			if (b > 0) {
				return Body.newInstance(one);
			}
			return Body.newInstance(501, "修改有误");
		}
		return Body.newInstance(501, "未有此条套餐信息");
	}

	public Body taocanListAll() {
		Taocan taocan = new Taocan();
		List<Taocan> list = taocan.selectAll();
		if (list.size() > 0) {
			return Body.newInstance(list);
		}
		return Body.BODY_500;
	}
	public ResultVo taocanList(PageVo pv, String userId) {
		if (pv.getPage() != null && pv.getPageSize() != null) {
			PageHelper.startPage(pv.getPage(), pv.getPageSize());
		}
		PageResult pr = PageResult.result(taocanMapper.TaocanList());
		ResultVo rv = new ResultVo();
		rv.setList(pr.getRows());
		rv.setTotal(pr.getTotal());
		return rv;
	}


}
